package action

import (
	"context"
	"trusteva/app/rbac/model"

	"trusteva/app/rbac/internal/svc"
	"trusteva/app/rbac/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ActionUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewActionUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ActionUpdateLogic {
	return &ActionUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ActionUpdateLogic) ActionUpdate(req *types.ActionUpdateRo) (resp *types.BaseRsp, err error) {
	err = l.svcCtx.DB.WithContext(l.ctx).Where("Id=?", req.ActionId).
		Select("Name", "Path", "Method", "Status").
		Updates(&model.ActionConfig{
			Name:   req.Name,
			Path:   req.Path,
			Method: req.Method,
			Status: model.LimitStatus(req.Status),
		}).Error
	return
}
